﻿#ifndef COMFUNC_H
#define COMFUNC_H

#include <qglobal.h>//基本数据类型
#include <QDebug>
#include <QMessageBox>
#include <QString>
#include <QRegularExpression>
#include <stdio.h>
#include "Typedefine.h"
#include "Constant.h"

/* 宏定义 *********************************************************************/
#define USE_CRC_TABLE_FOR_CALCULATION    (TRUE)             // 使用查表方式
#define u16CRC_POLYNOMIAL               ((U16) 0x1021)      // 多项式
#define u16TEST_HI_BIT_ON_MASK          ((U16) 0x8000)      // 高位掩码
#define u16ZERO_UPPER_BYTE_MASK         ((U16) 0x00FF)      // 高字节零掩码
#define u16CRC_SEED                     ((U16) 0x1021)      // 初始值

U16 CRC_CalcValue(U8* pu8Buf, U32 u32Len, U16 u16Seed);

#define uint8 quint8
#define array_size(array) (sizeof(array)/sizeof(*array))

uint8 checksum(uint8 *data,uint8 len);
QString byte_num_to_hex_string_with_space(const QByteArray &ByteArray);
QString byte_num_to_hex_string_with_space(uint8 *data, int len);
QString byte_num_to_hex_string_with_space(uint8 *data, int len, bool direction_is_forward);
void DectoBCD(int Dec, unsigned char *Bcd, int length);
uint8 bin2bcd(uint8 bin_byte);
quint32 bcd_le2hex(uint8_t bcd[], uint8 len);
void hex2bcd_le(quint32 value, uint8_t *bcd, uint8 bytes);
void memadd(void* dest, char data, int  len);
int hex_str_to_byte_arr(QString str, uint8 *byte_arr, int buff_size, bool direction_is_forward);
void put_le_val(quint32 val, uint8_t * p, uint8_t bytes);
void put_be_val(quint32 val, uint8 * p, uint8 bytes);
quint64 get_le_val(void * p, uint8_t bytes);
quint64 get_be_val(uint8_t * p, uint8_t bytes);
void print_arr(void *arr, int len);

#endif // COMFUNC_H
